<?php session_start();
error_reporting(E_ALL);
if(!isset($_SESSION['loggin']))
{
	die('You did not login, Please login first!');
}
?>
<html><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>DrinkDelivery</title>
<!-- InstanceEndEditable -->
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="login">
<img src="image/logo.jpg" width="100" height="30" align="middle">
 <p> <font size="+2" color="#FFFFFF"><a href="CU.html">                                           Contact Us</a></font></p>
<a href="logout.php"><img src="image/logout.png" align="right"></a>
<a href="login.php"><img src="image/login.png" align="right"></a> 
</div>
<div id="header">
<ul>
  <li></li>
<li><a href="store.php"><img src="image/m2.jpg" width="200" height="200"></a></li>
<li><a href="member.php"><img src="image/m3.jpg" width="200" height="200"></a></li>
<li><a href="category.php"><img src="image/m4.jpg" width="200" height="200"></a></li>
</ul>
</div>
<br/>
<div id="content">
<!-- InstanceBeginEditable name="content" -->
<div id="member">
<?php
		$connection = mysql_connect("localhost", "root", "");
		if ( !$connection ) {
			die('Could not connect to localhost.');	
		}
		$db = mysql_select_db("test", $connection);
		if ( !$db) {
			die ('Could not find database test.');	
		}
		
		if (isset($_POST['submit'])) 
{
		$cart_check = "select * from carts where id = '".$_POST['pay']."'";
		$num_check = mysql_query($cart_check,$connection);
		$result = mysql_num_rows($num_check);		
		if($result==0)
		{
			die('please enter valid carts, thanks!');
		}
		
		$dl = "DELETE FROM carts WHERE id='".$_POST['pay']."'";
			mysql_query($dl,$connection)or die(mysql_error()); 
		
		$row = mysql_fetch_array($num_check);
		
		$_SESSION['p_name']=$row['p_name'];
		$_SESSION['p_price']=$row['p_price'];
		$_SESSION['cart_qua']=$row['quantity'];
		
		$sqlstr = "insert into bill ( member_name, p_name,p_price,buy_qua,date) values('" . $_SESSION['username'] . "','" . $_SESSION['p_name'] . "','" . $_SESSION['p_price'] . "','" . $_SESSION['cart_qua'] . "',NOW())"; 	
		?>
        <br/><?php
		echo $sqlstr;?><?php
		
		$inst = mysql_query($sqlstr);
		if (!$inst)
 	 {
  		die('Error: ' . mysql_error());
 	 }
	 else
	 ?>
     <br>
     <?php
		echo "1 new user added";
		unset($_SESSION['p_name']);
		unset($_SESSION['p_price']);		
		unset($_SESSION['cart_qua']);
}
?>
<?php
if(isset($_REQUEST['bdele']))
		{
			$dl = "DELETE FROM bill WHERE id='".$_POST['del']."'";
			mysql_query($dl,$connection)or die(mysql_error());  
			?>
            <br>
            <?php
		}?>
        <h1 align="center">transcation history</h1>
<table border="1" cellpadding="10px" cellspacing="0" align="center">
    <tr>
    <th>Bill ID</th>
    <th>Product</th>
    <th>price</th>
    <th>Quantity</th>    
	<th>Date</th>            
    </tr>
<?php
		$pbill = "select * from bill where member_name = '".$_SESSION['username']."'";
		$result = mysql_query($pbill,$connection);
		while ($row = mysql_fetch_array($result)) {
			echo "<tr>";
			echo "<td>" . $row['id'] . "</td>";
			echo "<td>" . $row['p_name'] . "</td>";
			echo "<td>" . $row['p_price'] . "</td>";
			echo "<td>" . $row['buy_qua'] . "</td>";
			echo "<td>" . $row['date'] . "</td>";			
			echo "</tr>";										
		}
		mysql_close($connection);	
?>
</table>
<p>
</p>
<form action="bill.php" method="post">
<table border="1"  cellpadding="10px" cellspacing="0" align="center">
    <tr>
    <th>Please Enter the deleted Bill ID:</th>
    <td>
    <input type="text" name="del" size="9" /> 
    </td>
    <td><input type="submit" name="bdele" value="Delete" />
    </td>
    </tr>
</table>
</form>
</div>
<div id="memberfunction">
<img src="id/xiaohei.jpg" width="300"
height="300">
<br/><a href="member.php"><img src="image/detail.jpg" width="100" height="50" align="middle"></a>
<a href="change.php"><img src="image/change.jpg" width="100" height="50" align="right"></a>
<br /><a href="chart.php"><img src="image/chat.jpg" width="100" height="50" align="middle"></a>
<a href="feedback.php"><img src="image/feedback.jpg" width="100" height="50" align="right"></a>
</div>
<!-- InstanceEndEditable -->
</div>
<a href="index.php">z</a> </div>
</body>
<!-- InstanceEnd --></html>